package com.liangchen.astools.ui.homeinfo

import android.os.Bundle
import android.view.*
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.liangchen.astools.AsManager
import com.liangchen.astools.R
import com.liangchen.astools.info.AsDecoration
import com.liangchen.astools.info.InfoItemAdapter

class BaseInfoFragment : Fragment() {
    private var homeViewModel: HomeViewModel? = null
    override fun onCreateView(inflater: LayoutInflater,
                              container: ViewGroup?, savedInstanceState: Bundle?): View? {
        homeViewModel = ViewModelProvider(this).get(HomeViewModel::class.java)
        val asInfoManager = AsManager.getAsInfoManager()
        val layoutManager = LinearLayoutManager(context)
        val root = inflater.inflate(R.layout.fragment_debug_info, container, false)
        val recyclerView: RecyclerView = root.findViewById(R.id.recycler_view_debug_info)
        recyclerView.layoutManager = layoutManager
        val adapter = asInfoManager?.initInfoItems()?.let { InfoItemAdapter(it) }
        recyclerView.adapter = adapter
        context?.let { AsDecoration(it, AsDecoration.VERTICAL_LIST) }
            ?.let { recyclerView.addItemDecoration(it) }

        //final TextView textView = root.findViewById(R.id.text_home);
        /* homeViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
            @Override
            public void onChanged(@Nullable String s) {
                textView.setText(s);
            }
        });*/return root
    }
}